package softtech.apps.callblocker;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import android.content.Context;
import android.widget.Toast;

public class TextEnable {

	private static String file = "dataUseApp";
	/**
	 * check enable/disable app
	 * @return
	 */
	public static int getEnableApp(Context context){
		String Enable = null;
		//Toast.makeText(getApplicationContext(), ""+Enable, Toast.LENGTH_LONG).show();
		if(fTextRead(Enable,context).contentEquals("1"))
		return 1;
		return 0;
	}
	/**
	 * create file text save status enable/disalbe app
	 * @param Enable : text create
	 */
	public static  void fTextCreate(String Enable,Context context){
		 try {
             FileOutputStream fOut = context.openFileOutput(file,context.MODE_WORLD_READABLE);
             fOut.write(Enable.getBytes());
             fOut.close();
          } catch (Exception e1) {
             
             e1.printStackTrace();
          }
	}
	/**
	 * read file
	 * @param Enable:if enable is 1 and use block, enable is 0 and stop block
	 */
	private static String fTextRead(String Enable, Context context){
		try{
	         FileInputStream fin = context.openFileInput(file);
	         int c;
	         String temp="";
	         while( (c = fin.read()) != -1){
	            temp = temp + Character.toString((char)c);
	         }
	         Enable = temp;
	      }catch(Exception e){
	    	Enable= "1";
	        fTextCreate(Enable, context);
	      }
		return Enable;
	}
}
